package dataImport.action.manager;

import java.io.Serializable;
import dataImport.action.CommandReader;
import dataImport.action.ConfigurationReader;
import dataImport.action.CustomActionReader;
import dataImport.action.DescriptionReader;
import dataImport.action.NpcReader;
import dataImport.action.ObjectReader;
import dataImport.action.PlaceReader;
import dataImport.action.PredefinedActionReader;
import dataImport.action.RequirementReader;
import dataImport.action.ScenarioReader;
import dataImport.action.StateReader;
import dataImport.action.abstracts.AbstractEntityReader;
import dataImport.action.helper.XMLReader;


public class EntityReaderManager implements Serializable {

	private static final long serialVersionUID = 7031878582298068304L;

	private EntityReaderStorage entityReaderStorage;

	public EntityReaderManager() {
		this.entityReaderStorage = new EntityReaderStorage();

		this.getReader(EntityReaderStorageKey.NPC).read(XMLReader.getInstance().getDocument());
		this.getReader(EntityReaderStorageKey.OBJECT).read(XMLReader.getInstance().getDocument());
		this.getReader(EntityReaderStorageKey.PLACE).read(XMLReader.getInstance().getDocument());
		this.getReader(EntityReaderStorageKey.STATE).read(XMLReader.getInstance().getDocument());
	}

	private AbstractEntityReader getReader(final EntityReaderStorageKey entityReaderStorageKey) {
		if (!this.contains(entityReaderStorageKey)) {
			this.entityReaderStorage.add(entityReaderStorageKey, this);
		}

		return this.entityReaderStorage.get(entityReaderStorageKey);
	}

	public boolean contains(final EntityReaderStorageKey entityReaderStorageKey) {
		return this.entityReaderStorage.contains(entityReaderStorageKey);
	}

	public CommandReader getCommandReader() {
		return (CommandReader) this.getReader(EntityReaderStorageKey.COMMAND);
	}

	public CustomActionReader getCustomActionReader() {
		return (CustomActionReader) this.getReader(EntityReaderStorageKey.CUSTOM_ACTION);
	}

	public DescriptionReader getDescriptionReader() {
		return (DescriptionReader) this.getReader(EntityReaderStorageKey.DESCRIPTION);
	}

	public NpcReader getNpcReader() {
		return (NpcReader) this.getReader(EntityReaderStorageKey.NPC);
	}

	public ObjectReader getObjectReader() {
		return (ObjectReader) this.getReader(EntityReaderStorageKey.OBJECT);
	}

	public PlaceReader getPlaceReader() {
		return (PlaceReader) this.getReader(EntityReaderStorageKey.PLACE);
	}

	public PredefinedActionReader getPredefinedActionReader() {
		return (PredefinedActionReader) this.getReader(EntityReaderStorageKey.PREDEFINED_ACTION);
	}

	public RequirementReader getRequirementReader() {
		return (RequirementReader) this.getReader(EntityReaderStorageKey.REQUIREMENT);
	}

	public ScenarioReader getScenarioReader() {
		return (ScenarioReader) this.getReader(EntityReaderStorageKey.SCENARIO);
	}

	public StateReader getStateReader() {
		return (StateReader) this.getReader(EntityReaderStorageKey.STATE);
	}

	public ConfigurationReader getConfigurationReader() {
		return (ConfigurationReader) this.getReader(EntityReaderStorageKey.CONFIGURATION);
	}

	public void read() {
		this.getCommandReader().read(XMLReader.getInstance().getDocument());
		this.getCustomActionReader().read(XMLReader.getInstance().getDocument());
		this.getPredefinedActionReader().read(XMLReader.getInstance().getDocument());
		this.getRequirementReader().read(XMLReader.getInstance().getDocument());
		this.getConfigurationReader().read(XMLReader.getInstance().getDocument());
		this.getDescriptionReader().read(XMLReader.getInstance().getDocument());
		this.getScenarioReader().read(XMLReader.getInstance().getDocument());
	}
}
